package ljl.alg.wangzheng_camp.round1.tree;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class _429_level_ntree {
    
    public List<List<Integer>> levelOrder(Node root) {
        List<List<Integer>> res = new ArrayList<>();
        if (root == null) return res;
        LinkedList<Node> q = new LinkedList<>();
        q.offer(root);
        while (!q.isEmpty()) {
            LinkedList<Integer> level = new LinkedList<>();
            res.add(level);
            int size = q.size();
            for (int i = 0; i < size; i++) {
                Node node = q.poll();
                level.add(node.val);
                for (Node child : node.children) {
                    q.offer(child);
                }
            }
        }
        return res;
    }
    
}
